package net.ddrjw.soft.test;

import net.ddrjw.soft.log.LogDog;



/**
 * 这是一个演示多线程操作的程序
 * 
 * @author Administrator
 * 
 */
public class ThreadDemo extends Thread implements Runnable {

	/*
	 * @Override public void run() { while (true) { System.out.println("Thread "
	 * + threadNumber + "(" + countDown + ")"); if(--countDown == 0) return; }
	 * 
	 * }
	 */
	private static Integer i = 0;

	public static void main(String[] args) {
		LogDog.logger.info("线程开始 ");
		// 创建主线程
		Thread th = Thread.currentThread();
		System.out.println("当前主线程是" + th);

		// 启动子线程
		ThreadDemo demo = new ThreadDemo();
		Thread tt = new Thread(demo);
		tt.start();
		for (; i < 100; i++) {
			//synchronized (i) {
				String s="A--:";
				print(s);
				try {
					sleep(100);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			//}
			//print();
		}
		//System.out.println("---------------------" + activeCount());
	}

	public void run() {
		//System.out.println("子线程开始");
		for (; i < 100; i++) {
			//synchronized (i) {
				String s="B-----:";
				print(s);
				try {
					sleep(100);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			//}
		}
		//System.out.println("子线程结束" + Thread.currentThread());

	}
	public static synchronized void print(String Str){
		System.out.println(Str+i);
	}

}
